/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import gestion.DBGestionUsuario;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import negocio.Usuario;

/**
 *
 * @author David
 */
public class ControlUsuario {

    private DBGestionUsuario dbgu = new DBGestionUsuario();
    private Usuario us;
    ResultSet rs;

    public Usuario buscarUsId(int id) {
        rs = null;
        us = new Usuario();
        rs = dbgu.bUsuariosID(id);
        try {
            while (rs.next() == true) {
                us.setId(rs.getInt(1));
                us.setNombre(rs.getString(2));
                us.setApellido(rs.getString(3));
                us.setTelefono(rs.getString(4));
                us.setFoto(rs.getString(5));
            }
        } catch (SQLException ex) {
            Logger.getLogger(ControlUsuario.class.getName()).log(Level.SEVERE, null, ex);
        }
        return us;
    }

    public void eliminarUsId(int id) {
        dbgu.eUsuariosID(id);
    }

    public void modificarUs(int id, String n, String a, String t, String f) {
        us = new Usuario(id, n, a, t, f);
        dbgu.mUsuarios(us);
    }

    public void modificarFotoUs(String s, int i) {
        us = new Usuario();
        us.setFoto(s);
        us.setId(i);
        dbgu.mFotoUs(us);
    }

    public Object mostrarUs() {
        Object[][] o = null;
        rs = null;
        int filas = 0;
        rs = dbgu.mosUsuarios();
        try {
            while (rs.next() == true) {
                filas = rs.getRow();
            }
            o = new Object[filas][4];
            rs = dbgu.mosUsuarios();
            int i = 0;
            while (rs.next() == true) {
                o[i][0] = rs.getInt(1);
                o[i][1] = rs.getString(2);
                o[i][2] = rs.getString(3);
                o[i][3] = rs.getString(4);
                i++;
            }
        } catch (SQLException ex) {
            Logger.getLogger(ControlUsuario.class.getName()).log(Level.SEVERE, null, ex);
        }
        return o;
    }

    public int maxId() {
        return dbgu.maxId();
    }

    public int minId() {
        return dbgu.minId();
    }

    public int countUs() {
        return dbgu.countUs();
    }

    public void nueUsuario(String n, String a, String t, String f) {
        us = new Usuario();
        us.setId(dbgu.maxId() + 1);
        us.setNombre(n);
        us.setApellido(a);
        us.setTelefono(t);
        us.setFoto(f);
        System.out.println(us.getFoto());
        dbgu.nueUsarios(us);
    }

    public void cerrarCon() {
        this.cerrarCon();
    }
}
